﻿using System;
using System.Collections.Generic;
using System.Text;

using RRRSRoguelike.Managers;

namespace RRRSRoguelike.Helpers
{
	//FIXME:  Rename SessionVARS(or use the existing Session class) and make it do a single job, holding variables 
    /// <summary>
    /// This class holds session variables.
    /// </summary>
    public static class SeedHelper
    {
        #region Variables

        private static Random GeneralRandom = new Random();
        private static StringBuilder seedString = new StringBuilder();

        #endregion

        #region Properties



        #endregion

        #region Methods

        /// <summary>
        /// Sets the session variable for a specific dungeon seed
        /// </summary>
        /// <param name="seed"></param>
        public static void SetSeed(int seed)
        {
            ApplicationManager.Instance.Profile.Session.UseTempSeed = true;
            ApplicationManager.Instance.Profile.Session.TempSeed = seed;
        }

        /// <summary>
        /// Sets the session variable for a random dungeon seed
        /// </summary>
        public static void SetSeed()
        {
            ApplicationManager.Instance.Profile.Session.UseTempSeed = false;
            ApplicationManager.Instance.Profile.Session.TempSeed = CreateRandomSeed(5);
            
        }

        /// <summary>
        /// Generates a random seed
        /// </summary>
        /// <param name="seedLength">Length of desired seed</param>
        /// <returns>Returns seed value</returns>
        private static int CreateRandomSeed(int seedLength)
        {
            seedString.Clear();
            seedString.Append(GeneralRandom.Next(1, 9).ToString());
            for (var i = 1; i < seedLength; i++)
            {
                seedString.Append(GeneralRandom.Next(0, 9).ToString());
            }

            return int.Parse(seedString.ToString());
        }

        #endregion
    }
}
